package wy.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.List;
import java.util.Map;

/**
 * @描述
 * @创建人 wangyue
 * @创建时间2020/12/1714:30
 */
@RequestMapping("feign")
@RestController
public class FeignController {

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private ShopService shopService;

    @GetMapping("getAll1")
    public ResponseEntity<String> getAll1(){
        ResponseEntity<String> forEntity = restTemplate.getForEntity("http://wthrcdn.etouch.cn/weather_mini?city=沈阳", String.class);
        return forEntity;
    }

    @GetMapping("getAll")
    public List<Shop> getAll(){
        return shopService.getAll();
    }
    @PostMapping("pageList")
    public Map<String,Object> pageList(@RequestBody(required =  false) Shop shop,
                                       @RequestParam(defaultValue = "3") int pageSize,
                                       @RequestParam(defaultValue = "1")int pageNum){
        return shopService.pageList(shop,pageSize,pageNum);
    }
    @GetMapping("getById/{id}")
    public Shop getById(@PathVariable Integer id){
        return shopService.getById(id);
    }
    @PostMapping("save")
    public void save(@RequestBody Shop shop){
        shopService.save(shop);
    }
}
